/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.model;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 *
 * @author Rik Bauwens
 */
public class ListObservable<T>
{
	Set<IListObserver<T>> observers = new LinkedHashSet<IListObserver<T>>();

	public void addObserver(IListObserver<T> o)
	{
		if (!observers.contains(o))
			observers.add(o);
	}

	public boolean containsObserver(IListObserver<T> o)
	{
		return observers.contains(o);
	}

	public void removeObserver(IListObserver<T> o)
	{
		observers.remove(o);
	}

	public void itemAdded(T item)
	{
		for (IListObserver<T> o: observers)
                    o.itemAdded(item);               			
	}
        
	public void itemRemoved(T item)
	{
		for (IListObserver<T> o: observers)
			o.itemRemoved(item);
	}
}
